[...slug].vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <!-- 店铺商品列表 @zjf-2020-12-30 -->
  2. <template>
  3. <div class="self_background">
  4. <StoreHeaderCat ref="headercat" @sendGoodsName="sendGoodsName"/>
  5. <div
  6. class="sld_store_goods_list clearfix"
  7. :class="{ skeleton_sld_store_goods_list: firstLoading }"
  8. >
  9. <!-- 左侧分类 start -->
  10. <div
  11. class="left_cat_wrap"
  12. v-show="firstLoading ? true : storeData.cat.length"
  13. >
  14. <template
  15. v-for="(item, index) in firstLoading
  16. ? skeletonData.category
  17. : storeData.cat"
  18. :key="index"
  19. >
  20. <dl
  21. :class="{
  22. store_cat_item: true,
  23. on: !(item.openFlag != undefined && !item.openFlag),
  24. }"
  25. >
  26. <dt class="grade_one_cat">
  27. <router-link
  28. :to="'/store/goods/'+ calcProductName(storeName) +'_v-'+ vid + '_c-' + item.innerLabelId"
  29. >
  30. {{ item.innerLabelName }}
  31. </router-link>
  32. <i
  33. v-if="item.children.length"
  34. class="more"
  35. @click="toggleOpenFlag(index)"
  36. ></i>
  37. </dt>
  38. <dd
  39. v-if="
  40. item.children.length &&
  41. !(item.openFlag != undefined && !item.openFlag)
  42. "
  43. >
  44. <router-link
  45. v-for="(item_child, index_child) in item.children"
  46. :key="index_child"
  47. :to="'/store/goods/'+ calcProductName(storeName) +'_v-'+ vid + '_c-' + item_child.innerLabelId"
  48. >
  49. {{ item_child.innerLabelName }}
  50. </router-link>
  51. </dd>
  52. </dl>
  53. </template>
  54. </div>
  55. <!-- 左侧分类 end -->
  56. <!-- 右侧商品 start -->
  57. <div
  58. :class="{
  59. right_goods_wrap: true,
  60. fr: storeData.cat.length,
  61. no_cate_goods_wrap: !storeData.cat.length,
  62. }"
  63. >
  64. <div class="store_goods_search_nav">
  65. <span :class="{ active: sort == 0 }" >{{
  66. L["综合"]
  67. }}</span>
  68. <div class="sld_store_goods_total_num">
  69. {{ L["共"] }} {{ storeData.goods.pagination.total
  70. }} {{ L["件相关商品"] }}
  71. </div>
  72. </div>
  73. <ul class="sld_store_goods_list_wrap">
  74. <li
  75. v-for="(item, index) in firstLoading
  76. ? skeletonData.goods
  77. : storeData.goods.list"
  78. :key="index"
  79. >
  80. <div class="sld_goods_img">
  81. <router-link
  82. target="_blank"
  83. :to="'/goods/detail/'+ calcProductName(item.goodsDefaultName) +'_'+ item.defaultProductId"
  84. >
  85. <img :src="item.goodsImage" style="display: block" />
  86. </router-link>
  87. </div>
  88. <div class="sld_goods_name_wrap">
  89. <router-link
  90. target="_blank"
  91. :to="'/goods/detail/'+ calcProductName(item.goodsDefaultName) +'_'+ item.defaultProductId"
  92. :title="item.goodsName"
  93. v-html="item.goodsName"
  94. class="sld_goods_name"
  95. >
  96. </router-link>
  97. </div>
  98. <p class="clearfix">
  99. <span class="sld_goods_price fl"
  100. ><em>{{
  101. item.goodsMoney == null ? "Contact us to give you an individual quote" : item.goodsMoney
  102. }}</em></span
  103. >
  104. </p>
  105. <div class="promotion_tag">
  106. <template v-if="item.activityList && item.activityList.length">
  107. <div style="display: flex">
  108. <div
  109. v-for="(item_activity, index_activity) in item.activityList"
  110. :key="index_activity"
  111. >
  112. <span class="promotion_tag_text">{{
  113. item_activity.promotionName
  114. }}</span>
  115. </div>
  116. </div>
  117. </template>
  118. <button
  119. class="sld_collect_wrap fr flex_row_center_center"
  120. :class="{ collect_active: item.isFollowGoods }"
  121. @click="collect(item.defaultProductId, item.isFollowGoods)"
  122. >
  123. <img
  124. src="/goods/collection.png"
  125. alt=""
  126. v-show="item.isFollowGoods == true"
  127. style="width: 20px; height: 20px"
  128. />
  129. <img
  130. src="/goods/no_collection.png"
  131. alt=""
  132. v-show="item.isFollowGoods == false"
  133. style="width: 20px; height: 20px"
  134. />
  135. {{ L["收藏"] }}
  136. </button>
  137. </div>
  138. </li>
  139. </ul>
  140. <!-- 分页 start -->
  141. <div class="flex_row_center_center sld_pagination">
  142. <el-pagination
  143. @current-change="handleCurrentChange"
  144. v-model:currentPage.sync="pagitionCurrent"
  145. :page-size="storeData.goods.pagination.pageSize"
  146. layout="prev, pager, next"
  147. :total="storeData.goods.pagination.total"
  148. :hide-on-single-page="true"
  149. >
  150. </el-pagination>
  151. </div>
  152. <!-- 分页 end -->
  153. </div>
  154. <!-- 右侧商品 end -->
  155. <!-- 空页面 start-->
  156. <SldCommonEmpty
  157. v-if="!firstLoading && !storeData.goods.list.length"
  158. totalWidth="979"
  159. totalHeight="700"
  160. paddingTop="200"
  161. />
  162. <!-- 空页面 end-->
  163. </div>
  164. </div>
  165. </template>
  166. <script setup>
  167. import { ElMessage, ElPagination } from "element-plus";
  168. // import { lang_zn } from "@/assets/language/zh";
  169. import { getCurLanguage } from '@/composables/common.js';
  170. import { useFiltersStore } from "@/store/filter.js";
  171. const filtersStore = useFiltersStore();
  172. const proxy = getCurrentInstance();
  173. const route = useRoute();
  174. // const L = lang_zn;
  175. const L = getCurLanguage();
  176. const firstLoading = ref(true); //是否第一次加载
  177. const router = useRouter();
  178. const storeData = reactive({ cat: [], goods: { list: [], pagination: {} } }); //店铺数据,cat:店铺分类,goods:店铺商品列表
  179. const sort = ref(0); //0:默认/综合;1、销量从高到底;3、价格从低到高;4、价格从高到低;5、人气从高到低
  180. const headercat = ref(null); //获取dom的ref,名字同名
  181. const skeletonData = reactive({ category: [], goods: [] });
  182. const SEOinfo = reactive({
  183. seoTitle: "Products",
  184. seoDesc: "",
  185. seoKeywords: "",
  186. });
  187. //动态页面数据
  188. const vid = ref();
  189. const currentPage = ref(1); //分页——当前页
  190. const categoryId = ref(); //分类id
  191. const keyword = ref(); //搜索关键词
  192. const pagitionCurrent = ref(1)
  193. const storeName = ref('')
  194. //接收店铺名称
  195. const sendGoodsName = (val) => {
  196. storeName.value = val
  197. }
  198. const clacRouteParams = () => {
  199. if (calcUrlPagination(route.path)) {
  200. currentPage.value = calcUrlPagination(route.path)
  201. }
  202. if (calcUrlShopId(route.path)) {
  203. vid.value = calcUrlShopId(route.path)
  204. }
  205. if (calcUrlCatId(route.path)) {
  206. categoryId.value = calcUrlCatId(route.path);
  207. }
  208. if (calcUrlKeywords(route.path)) {
  209. keyword.value = calcUrlKeywords(route.path);
  210. }
  211. proxy.refs.headercat.setVid(calcUrlShopId(route.path));
  212. getStoreGoodsList();
  213. getStoreCatData();
  214. };
  215. watch(
  216. () => currentPage.value,
  217. (nv, ov) => {
  218. if (nv != ov) {
  219. pagitionCurrent.value = Number(nv)
  220. }
  221. }
  222. );
  223. //根据切换数据,改变SEO
  224. const setSEO = () => {
  225. if (categoryId.value == "") {
  226. useHead({
  227. title: "Products",
  228. meta: [
  229. {
  230. name: "description",
  231. content: "Products",
  232. },
  233. {
  234. name: "keywords",
  235. content: "Products",
  236. },
  237. ],
  238. });
  239. return;
  240. }
  241. for (let i in storeData.cat) {
  242. if (storeData.cat[i].innerLabelId == categoryId.value) {
  243. SEOinfo.seoTitle = storeData.cat[i].seoInfo.seoTitle;
  244. SEOinfo.seoDesc = storeData.cat[i].seoInfo.seoDesc;
  245. SEOinfo.seoKeywords = storeData.cat[i].seoInfo.seoKeywords;
  246. break;
  247. } else {
  248. for (let j in storeData.cat[i].children) {
  249. if (storeData.cat[i].children[j].innerLabelId == categoryId.value) {
  250. SEOinfo.seoTitle = storeData.cat[i].children[j].seoInfo.seoTitle;
  251. SEOinfo.seoDesc = storeData.cat[i].children[j].seoInfo.seoDesc;
  252. SEOinfo.seoKeywords =
  253. storeData.cat[i].children[j].seoInfo.seoKeywords;
  254. }
  255. }
  256. }
  257. }
  258. useHead({
  259. title: SEOinfo.seoTitle,
  260. meta: [
  261. {
  262. name: "description",
  263. content: SEOinfo.seoDesc,
  264. },
  265. {
  266. name: "keywords",
  267. content: SEOinfo.seoKeywords,
  268. },
  269. ],
  270. });
  271. };
  272. const initSkeletonData = () => {
  273. for (let i = 0; i < 5; i++) {
  274. skeletonData.category.push({
  275. innerLabelId: "",
  276. innerLabelName: "",
  277. openFlag: true,
  278. children: [
  279. { innerLabelId: "", innerLabelName: "0" },
  280. { innerLabelId: "", innerLabelName: "0" },
  281. { innerLabelId: "", innerLabelName: "0" },
  282. ],
  283. });
  284. }
  285. for (let i = 0; i < 8; i++) {
  286. skeletonData.goods.push({
  287. defaultProductId: "",
  288. goodsImage: "",
  289. goodsPrice: "",
  290. saleNum: "",
  291. activityList: [],
  292. isFollowGoods: false,
  293. });
  294. }
  295. };
  296. //获取店铺分类数据
  297. const getStoreCatData = async () => {
  298. const { data: value } = await useFetchRaw(
  299. apiUrl + "v3/seller/front/store/storeCategory?storeId=" + vid.value
  300. );
  301. const res = value._rawValue;
  302. if (res.state == 200) {
  303. storeData.cat = res.data;
  304. }
  305. setSEO();
  306. };
  307. //获取店铺商品列表
  308. const getStoreGoodsList = async () => {
  309. let param = {};
  310. let key = "";
  311. param.storeId = vid.value;
  312. key += vid;
  313. param.current = currentPage.value;
  314. key += currentPage.value;
  315. if (categoryId.value) {
  316. param.storeInnerLabelId = categoryId.value;
  317. key += categoryId.value;
  318. }
  319. if (keyword.value) {
  320. param.keyword = keyword.value;
  321. key += keyword.value;
  322. }
  323. // param.pageSize = 6;
  324. const { data: value, pending: pending } = await useFetchRaw(
  325. apiUrl + "v3/goods/front/goods/goodsList",
  326. { params: param, key: key, headers:{Authorization:'Bearer ' + filtersStore.getToken }}
  327. );
  328. const res = value._rawValue;
  329. if (!pending._rawValue) {
  330. firstLoading.value = false;
  331. }
  332. if (res.state == 200) {
  333. storeData.goods = res.data;
  334. }
  335. };
  336. const toggleOpenFlag = (key) => {
  337. storeData.cat[key].openFlag =
  338. storeData.cat[key].openFlag != undefined
  339. ? !storeData.cat[key].openFlag
  340. : false;
  341. };
  342. //分页切换/前往指定页面
  343. const handleCurrentChange = (val) => {
  344. currentPage.value = val;
  345. let path = "/store/goods/"+ calcProductName(storeName.value)+"_v-"+ vid.value +"_p-" + val
  346. if(keyword.value && !categoryId.value){
  347. path += "_k-" +keyword.value
  348. }
  349. else if(keyword.value && categoryId.value){
  350. path += "_c-" + categoryId.value +"_k-" +keyword.value
  351. }
  352. else if(!keyword.value && categoryId.value){
  353. path += "_c-" + categoryId.value
  354. }
  355. router.push({
  356. path: path
  357. });
  358. };
  359. watch(categoryId, (newValue, oldValue) => {
  360. if (newValue != oldValue) {
  361. setSEO();
  362. }
  363. });
  364. //收藏功能
  365. const collect = (defaultProductId, isFollowGoods) => {
  366. if (filtersStore.getLoginFlag) {
  367. //收藏功能
  368. let params = {
  369. productIds: defaultProductId,
  370. isCollect: !isFollowGoods,
  371. };
  372. post("v3/member/front/followProduct/edit", params).then((res) => {
  373. if (res.state == 200) {
  374. ElMessage.success(res.msg);
  375. storeData.goods.list.map((storeGoodsItem) => {
  376. if (storeGoodsItem.defaultProductId == defaultProductId) {
  377. storeGoodsItem.isFollowGoods = !storeGoodsItem.isFollowGoods;
  378. }
  379. });
  380. } else {
  381. ElMessage.error(res.msg);
  382. }
  383. });
  384. } else {
  385. //未登录的话提示登录
  386. return openLoginDialog({
  387. onRegister: () => {
  388. router.push({
  389. path: "/register",
  390. });
  391. },
  392. onForgot: () => {
  393. router.push({
  394. path: "/member/login/forget",
  395. });
  396. },
  397. });
  398. }
  399. };
  400. onMounted(() => {
  401. setTimeout(() => {
  402. sldStatEvent({ behaviorType: 'spv', storeId: vid.value ,pageUrl: defaultUrl + router.currentRoute.value.path, referrerPageUrl: apiUrl });
  403. }, 3000)
  404. initSkeletonData();
  405. nextTick(() => {
  406. clacRouteParams();
  407. });
  408. });
  409. </script>
  410. <style lang="scss" scoped>
  411. @import "@/assets/style/store/goodsList.scss";
  412. @import "@/assets/style/theme.scss";
  413. .el-pager li.active {
  414. color: $colorMain;
  415. cursor: default;
  416. }
  417. .el-pager li:hover {
  418. color: $colorMain;
  419. }
  420. .sld_pagination {
  421. margin: 20px 0 20px 0;
  422. }
  423. .store_goods_search_nav {
  424. cursor: pointer;
  425. }
  426. </style>